﻿using Admin.Auth;
using Admin.Service.Menus;
using Admin.Service.Menus.DTO;
using Admin.Service.UserRoles;
using BLL.UserInfos;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipes;
using System.Linq;

namespace Admin.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [CustomAuthorize]
    public class MenuController : ControllerBase
    {
        private readonly IMenuService menuService;

        public MenuController(IMenuService menuService)
        {
            this.menuService = menuService;
        }

        /// <summary>
        /// 主菜单显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]        
        public IActionResult GetTreeItem()
        {
            return Ok(menuService.GetMenu());
        }

        /// <summary>
        /// 菜单添加
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddTreeMenu(MenuDto dto)
        {
            return Ok(menuService.CreateMenu(dto));
        }

        /// <summary>
        /// 根据ID查询数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetMenuId(int id)
        {
            return Ok(menuService.GetMenuId(id));
        }

        /// <summary>
        /// 菜单添加
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        public IActionResult UpdMenu(MenuDto dto)
        {
            return Ok(menuService.UpdMenu(dto));
        }

        /// <summary>
        /// 菜单删除
        /// </summary>
        /// <returns></returns>
        [HttpDelete]
        public IActionResult Delete(int id)
        {
            return Ok(menuService.Delete(id));
        }

        /// <summary>
        /// 嵌套  负菜单显示
        /// </summary>
        /// <returns></returns>
        //private List<TreeShow> GetNegativeMenuId(int menuid)
        //{
        //    List<TreeShow> list = menuService.Menus().Where(x => x.MId == menuid).Select(s => new TreeShow
        //    {
        //        Value = s.MenuId,
        //        Label = s.MainMenuName,
        //        Path = s.Path,
        //        Children = null
        //    }).ToList();

        //    return list;
        //}
    }
}
